package com.jingxing.controller;

import com.jingxing.config.ApiResult;
import com.jingxing.config.UserLoginToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@Slf4j
@RestController
@RequestMapping("/trainingSignIn")
@Api(value = "API", tags = {"签到相关"})
@UserLoginToken
public class TrainingSignInController {
    @Autowired
    private RestTemplate restTemplate;

    private static final String URL_20001 = "http://JINGXINGPROJECT-SERVER";


    @PostMapping("/signIn")
    @ApiOperation("签到")
    public ApiResult signIn(String playerId, Integer trainingLevel) {
        MultiValueMap<String, Object> requestEntity = new LinkedMultiValueMap<>();
        requestEntity.add("playerId", playerId);
        requestEntity.add("trainingLevel", trainingLevel);
        return restTemplate.postForObject(URL_20001 + "/trainingSignIn/signIn", requestEntity, ApiResult.class);
    }

    @PostMapping("/getSignInByPlayerId")
    @ApiOperation("通过选手id查询对应签到记录")
    public ApiResult getSignInByPlayerId(String playerId) {
        MultiValueMap<String, Object> requestEntity = new LinkedMultiValueMap<>();
        requestEntity.add("playerId", playerId);
        return restTemplate.postForObject(URL_20001 + "/trainingSignIn/getSignInByPlayerId", requestEntity, ApiResult.class);
    }


}
